home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: ToolPalette.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1992 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* This file contains the code for the document procedure pointers for the DTS.Draw
- ** tool palette document. The tool palette document does very little, so most of
- ** the document procedure pointers are set to nil. Imaging and clicking are the
- ** only two methods that we need to support. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.Common.h" /* Get the stuff in common with rez. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __AppMenu__
- #include "App.Menu.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
- /*****************************************************************************/
-
-
-
- short gTool;
- Boolean gKeepTool;
- WindowPtr gToolWindow;
-
- static void ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
- static void DrawIcon(Rect *rct, short iconID);
- static WindowPtr GetToolWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
- WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
- static Rect PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Open an invisible tool palette. The user will have to tear off the menu before
- ** a tool palette is visible. */
-
- #pragma segment ToolPalette
- OSErr OpenToolPalette(void)
- {
- OSErr err;
- FileRecHndl frHndl;
-
- err = NewDocument(&frHndl, kToolFileType, false);
- if (!err) {
- err = DoNewWindow(frHndl, &gToolWindow, FrontWindow(), (WindowPtr)-1);
- if (err)
- DisposeDocument(frHndl);
- }
-
- if (err)
- HCenteredAlert(rErrorAlert, nil, (ModalFilterProcPtr)AlertFilter);
- else
- SetPaletteTool(0, false);
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Just imaging and clicking are handles by the tool palette. */
-
- #pragma segment ToolPalette
- OSErr ToolInitDocument(FileRecHndl frHndl)
- {
- FileRecPtr frPtr;
-
- frPtr = *frHndl;
- frPtr->fileState.windowID = rToolWindow;
- frPtr->fileState.getDocWindow = GetToolWindow;
- frPtr->fileState.calcFrameRgnProc = nil;
- frPtr->fileState.contentClickProc = ToolContentClick;
- frPtr->fileState.contentKeyProc = nil;
- frPtr->fileState.drawFrameProc = nil;
- frPtr->fileState.freeDocumentProc = nil;
- frPtr->fileState.freeWindowProc = nil;
- frPtr->fileState.imageProc = ToolImageDocument;
- frPtr->fileState.initContentProc = nil;
- frPtr->fileState.readDocumentProc = nil;
- frPtr->fileState.readDocumentHeaderProc = nil;
- frPtr->fileState.resizeContentProc = nil;
- frPtr->fileState.scrollFrameProc = nil;
- frPtr->fileState.undoFixupProc = nil;
- frPtr->fileState.windowCursorProc = nil;
- frPtr->fileState.writeDocumentProc = nil;
- frPtr->fileState.writeDocumentHeaderProc = nil;
-
- frPtr->fileState.fss.name[0] = 0; /* Use resource window name. */
- frPtr->fileState.attributes = kwToolWindow;
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Find out which tool was clicked or double-clicked on. */
-
- #pragma segment ToolPalette
- static void ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #pragma unused (firstClick)
-
- WindowPtr oldPort;
- Point pt;
- short tool;
- long tick;
- static long lastClick;
-
- SetPort(window); /* We are supposed to be here. */
-
- GetPort(&oldPort);
- SetPort(window);
- pt = event->where;
- GlobalToLocal(&pt);
-
- tool = pt.v / kToolHeight;
- tick = TickCount();
-
- if (tool < kNumTools) {
- gKeepTool = false;
- if (tick < (lastClick + 20))
- if ((tool) && (tool == gTool))
- gKeepTool = true;
- gTool = tool;
- lastClick = tick;
- SetPaletteTool(gTool, gKeepTool);
- }
-
- SetPort(oldPort);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Draw the tool palette icons into the port. If DTS.LIB..framework calls us, the
- ** port is already set, but we set it here so that we can call this function
- ** directly. Calling it directly is desireable for certain operations, such
- ** as when the user clicks with a one-shot tool. When this occurs, we revert
- ** back to the arrow tool. Also, if a tool is permanently selected and the
- ** user clicks in a document but then doesn't grow out an object, we also revert
- ** to the arrow tool. Another case is if the user selects a tool via the menu. */
-
- #pragma segment ToolPalette
- OSErr ToolImageDocument(FileRecHndl frHndl)
- {
- #pragma unused (frHndl)
-
- WindowPtr oldPort;
- short i, j;
- Rect iconRect;
-
- GetPort(&oldPort);
- SetPort(gToolWindow);
-
- for (i = 0; i < kNumTools; ++i) { /* Draw an icon for each tool. */
- iconRect.left = 0;
- iconRect.top = i * kToolHeight;
- iconRect.right = 32;
- iconRect.bottom = iconRect.top + kToolHeight - 1;
- if ((j = i) == gTool) {
- j += 50;
- if (gKeepTool)
- j += 50;
- }
- DrawIcon(&iconRect, j + rArrowIcon);
- MoveTo(0, iconRect.top + kToolHeight - 1);
- Line(32, 0);
- }
-
- SetPort(oldPort);
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- #pragma segment ToolPalette
- static void DrawIcon(Rect *rct, short iconID)
- {
- Handle iconHndl;
- Rect rct32;
- RgnHandle oldClip, newClip;
-
- if (iconHndl = GetResource('ICN#', iconID)) {
- GetClip(oldClip = NewRgn());
- newClip = NewRgn();
- RectRgn(newClip, rct);
- SetClip(newClip);
- rct32.right = (rct32.left = rct->left) + 32;
- rct32.bottom = (rct32.top = rct->top ) + 32;
- PlotIcon(&rct32, iconHndl);
- SetClip(oldClip);
- DisposeRgn(oldClip);
- DisposeRgn(newClip);
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This code is used if the application is modified to start with a visible tool
- ** palette. There didn't used to be a tool menu, and the palette was simply
- ** displayed upon boot time. This code positions the window in the upper-right
- ** of the main screen. */
-
- #pragma segment ToolPalette
- WindowPtr GetToolWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
- WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon)
- {
- return(GetSomeKindOfWindow(PlaceToolWindow, id, storage, vis, relWindow,
- behind, inColor, sizeInfo, refCon));
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Proc for the function GetToolWindow(). */
-
- #pragma segment ToolPalette
- Rect PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo)
- {
- #pragma unused (relatedWindow, sizeInfo)
-
- Rect scnRct, cntRct;
- short dx, dy;
-
- scnRct = GetMainScreenRect();
- cntRct = GetWindowContentRect(window);
-
- dx = cntRct.right - cntRct.left;
- dy = cntRct.bottom - cntRct.top;
-
- cntRct.right = scnRct.right - 5;
- cntRct.top = scnRct.top + 33;
- cntRct.left = cntRct.right - dx;
- cntRct.bottom = cntRct.top + dy;
-
- MoveWindow(window, cntRct.left, cntRct.top, false);
- return(cntRct);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Tool palette display housekeeping function. */
-
- #pragma segment ToolPalette
- void ToolPaletteDisplay(void)
- {
- if (((WindowPeek)gToolWindow)->visible)
- HideWindow(gToolWindow);
- else {
- ShowHide(gToolWindow, true);
- BringToFront(gToolWindow);
- HiliteWindows();
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Tool palette set tool function. */
-
- #pragma segment ToolPalette
- void SetPaletteTool(short tool, Boolean keepTool)
- {
- MenuHandle menu;
- short i;
-
- gTool = tool;
- gKeepTool = keepTool;
- ToolImageDocument(nil);
-
- menu = GetMHandle(mToolPalette);
- for (i = iArrowTool; i <= iPieTool; ++i) SetItemMark(menu, i, noMark);
- SetItemMark(menu, gTool + 1, '1' + keepTool);
- }
-
-
-
-